//
//  DBParser.h
//  parser
//
//  Created by Daniel Braun on 04/05/07.
//  Copyright 2007 __MyCompanyName__. All rights reserved.
//

#import <Cocoa/Cocoa.h>

#import "DBParserRule.h"
#import "DBParserRuleTerminal.h"
#import "DBParserRuleChoice.h"
#import "DBParserRuleOptional.h"
#import "DBParserRuleNamed.h"

@class DBLexerTokenMatch;
@class DBParser;
@class DBParserAstNode;


@interface DBParser : NSObject {
	DBParserRule *rule;
	NSArray *tokens;
	int tindex;
	int tnum;
	id target;
	
	Class nodeClass;
	DBParserAstNode *curNode;
	NSMutableArray *nodeStack;
}

- (void) setRule:(DBParserRule *) r;
- (void) parseTokens:(NSArray *) tokens;
- (void) reset;

/* called by rules */
- (DBLexerTokenMatch *) _lookAhead0;
- (DBLexerTokenMatch *) _lookAhead:(int)k;
- (int) _tlookAhead0;
- (int) _tlookAhead:(int)k;

- (void) _consume;
- (void) _nomatch:(DBParserRule *)r;
- (void) _triggerAction:(SEL) act;

- (void) setTarget:(id)t;
- (id) target;

- (void) setNodeClass:(Class)c;
- (void) addAstNode:(DBLexerTokenMatch*)tok astDef:(NSString *)astDef;
- (void) astPush;
- (void) astPop;

- (DBParserAstNode *) ast;

@end


